package com.word.app.controller.response;

import java.util.HashMap;

public class BaseResponse extends HashMap<String, Object> {

    private static final long serialVersionUID = -8713837118340960775L;

    public BaseResponse(){
        this.addCodeMessage(Code.C200);
    }

    public BaseResponse(Code code){
        this.addCodeMessage(code);
    }

    public BaseResponse message(String message) {
        this.put("message", message);
        return this;
    }

    public BaseResponse code(String code) {
        this.put("code", code);
        return this;
    }


    public BaseResponse data(Object data) {
        this.put("data", data);
        return this;
    }

    @Override
    public BaseResponse put(String key, Object value) {
        super.put(key, value);
        return this;
    }

    public BaseResponse addCodeMessage(Integer code,String message,Object data) {
        this.put("code", code);
        this.put("message", message);
        this.put("data", data);
        return this;
    }

    public BaseResponse addCodeMessage(Code code, Object data) {
        this.put("code", code.getCode());
        this.put("message", code.getDesc());
        this.put("data", data);
        return this;
    }

    public BaseResponse addCodeMessage(Integer code,String message) {
        this.put("code", code);
        this.put("message", message);
        return this;
    }

    public BaseResponse addCodeMessage(Code code) {
        this.put("code", code.getCode());
        this.put("message", code.getDesc());
        return this;
    }
}
